package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.transformation.editor.model.GraphicalDomain;
import edu.pku.sei.transformation.editor.model.pattern.INodeTemplate;

public class NodeTemplateDeleteCommand extends Command {
	private GraphicalDomain domain;
	private INodeTemplate variable;

	public NodeTemplateDeleteCommand(INodeTemplate variable,
			GraphicalDomain domain) {
		this.variable = variable;
		this.domain = domain;
	}

	@Override
	public boolean canExecute() {
		if (this.variable != null && this.domain != null) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public void execute() {
		this.domain.getPattern().getNodes().remove(variable);
		variable.setPattern(null);
	}

	@Override
	public void undo() {
		this.domain.getPattern().getNodes().add(variable);
		variable.setPattern(domain.getPattern());
		this.domain.bindNewVariable2Exp();
	}
}
